package com.woniu.account.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.woniu.account.dao.CoachDao;
import com.woniu.account.dto.coachResume.CoachResumeDto;
import com.woniu.account.form.coachResume.AddCoachResumeFrom;
import com.woniu.account.form.coachResume.UpdateCoachResumeFrom;
import com.woniu.account.model.Coach;
import com.woniu.account.model.CoachResume;
import com.woniu.account.dao.CoachResumeDao;
import com.woniu.account.service.CoachResumeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.exception.YuJiaException;
import com.woniu.util.StateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月11日
 */
@Service
public class CoachResumeServiceImpl extends ServiceImpl<CoachResumeDao, CoachResume> implements CoachResumeService {
    @Autowired
    private CoachResumeDao coachResumeDao;
    @Autowired
    private CoachDao coachDao;
    @Override
    public void add(AddCoachResumeFrom from) {
        Coach coach = coachDao.selectById(from.getCoachId());
        if (ObjectUtil.isEmpty(coach)) {
            throw new YuJiaException(500, "没有教练");
        }
        if (!(coach.getCoachState() == StateUtil.COACH__STATE_UNEMPLOYED||coach.getCoachState() == StateUtil.COACH__STATE_ON_JOB)) {
            throw new YuJiaException(500, "教练状态异常");
        }
        CoachResume coachResume = BeanUtil.toBean(from, CoachResume.class);
        coachResume.setCoachJobResumes(from.getJobResumes().toString());
        coachResume.setCoachCardImage(from.getCoachCardImages().toString());
        coachResume.setCoachHonor(from.getCoachHonors().toString());
        System.out.println(coachResume+"WWWWWWWWWWWW");
        coachResumeDao.insert(coachResume);
    }


    @Override
    public CoachResumeDto updateCoachResume(UpdateCoachResumeFrom from) {
        return null;
    }

    @Override
    public CoachResumeDto getCoachResumeById(Integer id) {
        CoachResumeDto coachResumeDto = coachResumeDao.getCoachResumeById(id);
        System.out.println(coachResumeDto);
        System.out.println(coachResumeDao.selectById(id));
        return coachResumeDto;
    }
}
